package com.mytest.leetcode;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Solution189 {

    public static void main(String[] args) {
        Solution189 solution189 = new Solution189();
        int [] nums = {1,2,3,4,5,6,7};
        int k = 3;
        solution189.rotate(nums, k);
        log.info("{}", nums);
    }

    public void rotate(int[] nums, int k) {
        int length = nums.length;
        int realK = k%length;

        reverse(nums, 0, length -1);
        reverse(nums, 0, realK -1);
        reverse(nums, realK, length -1);

    }

    public static void reverse(int[] nums, int left, int right){
        while(left< right){
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
            left++;
            right--;
        }
    }
}
